package com.innjia.sys.service.impl;

import com.innjia.base.page.Page;
import com.innjia.base.page.PageHelper;
import com.innjia.base.utils.Query;
import com.innjia.sys.dao.UserAdminDao;
import com.innjia.sys.entity.UserAdminEntity;
import com.innjia.sys.entity.UserEntity;
import com.innjia.sys.service.UserAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author innjia
 */
@Service("userAdminService")
public class UserAdminServiceImpl extends UserServiceImpl implements UserAdminService {
    @Autowired
    private UserAdminDao userAdminDao;

    @Override
    public Page queryList(Map<String, Object> map) {
        Query query = (Query) map;
        PageHelper.startPage(query.getPage(), query.getLimit());
        userAdminDao.queryList(map);
        return PageHelper.endPage();
    }

    @Override
    public UserEntity queryByLoginName(String logName) {
        return userAdminDao.queryByLoginName(logName);
    }

    @Override
    public UserAdminEntity queryObject(String id) {
        return userAdminDao.queryObject(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void save(UserEntity user) {
        UserAdminEntity userAdmin = (UserAdminEntity) user;
        super.save(userAdmin);
        userAdmin.setUserId(userAdmin.getId());
        userAdminDao.save(userAdmin);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void update(UserEntity user) {
        UserAdminEntity userAdmin = (UserAdminEntity) user;
        super.update(userAdmin);
        userAdminDao.update(userAdmin);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(String id) {
        super.delete(id);
        userAdminDao.delete(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteBatch(String[] ids) {
        super.deleteBatch(ids);
        userAdminDao.deleteBatch(ids);
    }

}
